	<view class="container" v-if="!loading">
		<view class="main">
			<view class="nav">
				<view class="header">
					<view class="left">
						<view class="store-name">
							<view class="text-bold">{{addressTop}}</view>
							<image src="../../static/forward_active.png" style="width: 30rpx; height: 30rpx;" class="mr-10" @tap="getAddressList()"></image>
						</view>
						<view class="store-position">
							<image src="../../static/position.png" style="width: 30rpx; height: 30rpx;" class="mr-10">
							</image>
							<view class="text-gray"><text class="cuIcon-locationfill">距离您{{distance}}km</text></view>
						</view>
					</view>
					<view class="right flex-sub padding-lr-sm padding-top-sm margin-xs radius">
						<s-switch @switchValue="getSwitchValue()" :defaultValue="1" :switchList="arr"></s-switch>
						<!-- <view class="ziqu">
							<text>自取</text>
						</view>
						<view class="waimai">
							<text>外卖</text>
						</view> -->
					</view>
				</view>
				<view class="headtip">
					<text class="title">门店详细信息</text>
					<view>
						<text class="title">点此查看</text>
						<image src="../../static/forward.png" style="width: 30rpx; height: 30rpx;" class="mr-10">
						</image>
					</view>
				</view>
			</view>
			<view class="content">
				<scroll-view class="menus" :scroll-y="true" :style="{height: clientHeight?clientHeight+'px':'auto'}">
					<view class="wrapper">
						<view class="menu" v-for="(item,index) in goods" :key="index"
							:class="{'current': item.id === currentCateId}}" :id="`menu-${item.id}`"
							@tap="handleMenuTap(item.id)">
							<image :src="item.iconimg" class="icon"></image>
							<text>{{item.name}}</text>
							<view class="dot" v-show="menuCartNum(item.id)">
								{{menuCartNum(item.id)}}
								<!-- </view> -->
							</view>
						</view>
					</view>
				</scroll-view>
				<!-- 商品列表（静态） -->
				<scroll-view class="goods" scroll-with-animation scroll-y :scroll-top="cateScrollTop" @tap="handleGoodsScroll">
					<view class="wrapper">
						<view class="list">
							<!-- 列表标题	 -->
							<view class="category" v-for="(item,index) in goods" :key="index">
								<view class="title">
									<text>{{item.name}}</text>
								</view>
								<view class="items">
									<view class="good" v-for="(good,key) in item.good_list" :key="key">
										<image class="goodsimage" :src="good.img"></image>
										<view class="goodsitemright">
											<text class="goods.name">{{good.name}}</text>
											<text class="goodstips">{{good.content}}</text>
											<view class="price_and_action">
												<text class="price">￥{{good.price}}</text>
												<view class="btn-group" v-if="good.user_property">
													<button type="primary" class="btn property_btn" hover-class="none"
														size="mini" style="margin-right: 40rpx;"
														@tap="showGoodDetailModal(item,good)">
														选规格
													</button>
													<view class="dot"
														v-show="goodCartNum(good.key) > {{ goodCartNum(good.key) }}"
														class="padding-lr-xs" style="font-weight: 600;">
													</view>
													<!-- <view class="dot" v-show="goodCartNum(good.id)">{{ goodCartNum(good.id) }}</view> -->
												</view>
												<!-- 数量框 -->
												<view class="btn-group" v-else>
													<button type="default" v-show="goodCartNum(good.key)" plain
														class="btn reduce_btn" size="mini" hover-class="none"
														@tap="handleReduceFromCart(item,good)">
														-
													</button>
													<view class="number" v-show="goodCartNum(good.key)">
														{{ goodCartNum(good.key) }}
													</view>
													<button type="primary" class="btn add_btn" size="min"
														hover-class="none" @tap="handleAddToCart(item,good,1)">
														+
													</button>
												</view>
											</view>
										</view>
									</view>
								</view>
							</view>
						</view>
					</view>
				</scroll-view>
			</view>
			<!-- 底部购物车 -->
			<view class="cart-box" v-if="cart.length >= 0">
				<view class="mark">
					<image src="../../static/order/cart.png" class="cart-img"></image>
					<view class="tag">总金额</view>
					<!-- <view class="tag">{{ getCartGoodsNumber }}</view> -->
				</view>
				<view class="price">¥</view>
				<button type="primary" class="pay-btn" @tap="toPay()" :disabled="disabledPay()">
					{{disabledPay() ? `差15元起送`:`去结算`}}
				</button>
			</view>
		</view>
		<!--end-->
		<!-- 商品详情页 -->
		<modal :show="goodDetailModalVisible" class="good-detail-modal" color="#5A5B5C" width="90%" custom
			padding="0rpx" radius="12rpx">
			<view class="cover">
				<image v-if="good.images" :src="good.images" class="image"></image>
				<view class="btn-group">
					<image src="/static/order/order_share.png"></image>
					<image src="/static/order/order_close.png" @tap="closeGoodDetailModal()"></image>
				</view>
			</view>
			<scroll-view class="detail" scroll-y>
				<view class="wrapper">
					<view class="basic">
						<view class="name">{{ good.name }}</view>
						<view class="tips">{{ good.content }}</view>
					</view>
					<view class="properties" v-if="good.use_property">
						<view class="property" v-for="(item, index) in good.property" :key="index">
							<view class="title">
								<text class="name">{{ item.name }}</text>
							</view>
							<view class="values">
								<view class="value" v-for="(value, key) in item.values" :key="key"
									:class="{'default': value.is_default}" @tap="changePropertyDefault(index, key)">
									{{ value.value }}
								</view>
							</view>
						</view>
					</view>
				</view>
			</scroll-view>
			<view class="action">
				<view class="left">
					<view class="price">￥{{ good.price }}</view>
					<view class="props" v-if="getGoodSelectedProps(good)">
						{{ getGoodSelectedProps(good) }}
					</view>
				</view>
				<view class="btn-group">
					<button type="default" plain class="btn" size="mini" hover-class="none"
						@tap="handlePropertyReduce()">
						<view class="iconfont iconsami-select"></view>
					</button>
					<view class="number">{{ good.number }}</view>
					<button type="primary" class="btn" size="min" hover-class="none" @tap="handlePropertyAdd()">
						<view class="iconfont iconadd-select"></view>
					</button>
				</view>
			</view>
			<view class="add-to-cart-btn" @tap="handleAddToCartInModal()">
				<view>加入购物车</view>
			</view>
		</modal>
	</view>
	<view class="loading" v-else>
		<image src="../../static/animation.png"></image>
	</view>
</template>

<script>
	import SSwitch from "@/components/switch.vue"
	import modal from "@/components/modal.vue"
	import {
		goods
	} from "../../api/goods.js"
	
	export default {
		components: {
			SSwitch,
			modal,
		},
		data() {
			return {
				loading: true,
				//定义商品详情页
				goodDetailModalVisible: false,
				//定义地址列表
				addressTop: '',
				getPlistData: {
					//参数
					name: '',
					lat: '',
					lng: '',
					city: ''
				},
				dataList: [],
				distance: 3.6,
				goods: goods, //所有商品	
				sizeCalcState: false, //商品分类列表
				category: {},
				currentCateId: 1, //默认分类为1
				//当前饮品
				good: {
					key: 1,
					img: require("../../static/goods/001001.png"),
					name: '鲜草莓桃桃',
					number: 1,
					price: 18.5,
					unit: "件",
					use_property: 1,
					property: [{
							name: "杯型",
							values: [{
									value: "大杯",
									id: 0,
									is_default: 0,
								},
								{
									value: "中杯",
									id: 1,
									is_default: 1,
								},
							],
						},
						{
							name: "温度",
							values: [{
									id: 0,
									value: "常温",
									is_default: 0,
								},
								{
									id: 1,
									value: "沙冰",
									is_default: 1,
								},
								{
									id: 2,
									value: "热",
									is_default: 0,
								},
							],
						},
						{
							name: "甜度",
							values: [{
									id: 0,
									value: "七分糖",
									is_default: 0,
								},
								{
									id: 1,
									value: "不另外加糖",
									is_default: 0,
								},
								{
									id: 2,
									value: "正常糖",
									is_default: 1,
								},
							],
						}
					]
				},
				totalPrice: 0,
				totalNum: 0,
				modalName: 0,
				detailVisible: false,
				cateScrollTop: 0,
				menuScrollIntoView: '',
				cart: [], //购物车
				arr: [{
						key: 1,
						value: '外卖'
					},
					{
						key: 2,
						value: '自取'
					}
				],
				category: [{
						id: 1,
						name: '阿水当季必点',
						iconimg: require("../../static/menu/order_menu_1.png"),
						goodlist: [{
								id: 1,
								name: '鲜草莓桃桃',
								content: '“鲜甜桃肉x红颜草莓x茉莉绿茶 新鲜红颜草莓手工捣制，融入香甜桃子，搭配清新优雅的茉莉花香，满满果肉，清爽回甘！',
								price: 18.5,
								img: require("../../static/goods/001001.png"),
								num: 0
							},
							{
								id: 2,
								name: '杨枝甘露（中杯）',
								content: '“鲜甜桃肉x红颜草莓x茉莉绿茶 新鲜红颜草莓手工捣制，融入香甜桃子，搭配清新优雅的茉莉花香，满满果肉，清爽回甘！',
								price: 17,
								img: require("../../static/goods/001002.png"),
								num: 0
							},
							{
								id: 3,
								name: '霸气鲜草莓',
								content: '“鲜甜桃肉x红颜草莓x茉莉绿茶 新鲜红颜草莓手工捣制，融入香甜桃子，搭配清新优雅的茉莉花香，满满果肉，清爽回甘！',
								price: 16,
								img: require("../../static/goods/001003.png")
							},
							{
								id: 4,
								name: '葡萄多肉酪酪',
								content: '“鲜甜桃肉x红颜草莓x茉莉绿茶 新鲜红颜草莓手工捣制，融入香甜桃子，搭配清新优雅的茉莉花香，满满果肉，清爽回甘！',
								price: 18,
								img: require("../../static/goods/001004.png"),
								num: 0
							},
							{
								id: 5,
								name: '鸭屎香柠檬茶',
								content: '“鲜甜桃肉x红颜草莓x茉莉绿茶 新鲜红颜草莓手工捣制，融入香甜桃子，搭配清新优雅的茉莉花香，满满果肉，清爽回甘！',
								price: 16,
								img: require("../../static/goods/001005.png"),
								num: 0
							},
							{
								id: 6,
								name: '桃桃爆柠茶',
								content: '“鲜甜桃肉x红颜草莓x茉莉绿茶 新鲜红颜草莓手工捣制，融入香甜桃子，搭配清新优雅的茉莉花香，满满果肉，清爽回甘！',
								price: 16,
								img: require("../../static/goods/001006.png"),
								num: 0
							}
						]
					},
					{
						id: 2,
						name: '鲜果·茶',
						iconimg: require("../../static/menu/order_menu_2.png"),
						goodlist: [{
								id: 1,
								name: '蓝色夏威夷',
								content: '“鲜甜桃肉x红颜草莓x茉莉绿茶 新鲜红颜草莓手工捣制，融入香甜桃子，搭配清新优雅的茉莉花香，满满果肉，清爽回甘！',
								price: 15,
								img: require("../../static/goods/002001.png"),
								num: 0
							},
							{
								id: 2,
								name: '鲜柠檬百香果',
								content: '“鲜甜桃肉x红颜草莓x茉莉绿茶 新鲜红颜草莓手工捣制，融入香甜桃子，搭配清新优雅的茉莉花香，满满果肉，清爽回甘！',
								price: 13,
								img: require("../../static/goods/002002.png"),
								num: 0
							},
							{
								id: 3,
								name: '优格寒天',
								content: '“鲜甜桃肉x红颜草莓x茉莉绿茶 新鲜红颜草莓手工捣制，融入香甜桃子，搭配清新优雅的茉莉花香，满满果肉，清爽回甘！',
								price: 13,
								img: require("../../static/goods/002003.png"),
								num: 0
							},
							{
								id: 4,
								name: '蜂蜜柚子茶',
								content: '“鲜甜桃肉x红颜草莓x茉莉绿茶 新鲜红颜草莓手工捣制，融入香甜桃子，搭配清新优雅的茉莉花香，满满果肉，清爽回甘！',
								price: 10,
								img: require("../../static/goods/002004.png"),
								num: 0
							},
							{
								id: 5,
								name: '蜂蜜柠檬',
								content: '“鲜甜桃肉x红颜草莓x茉莉绿茶 新鲜红颜草莓手工捣制，融入香甜桃子，搭配清新优雅的茉莉花香，满满果肉，清爽回甘！',
								price: 10,
								img: require("../../static/goods/002005.png"),
								num: 0
							}
						]
					},
					{
						id: 3,
						name: '超人气奶茶',
						iconimg: require("../../static/menu/order_menu_3.png"),
						goodlist: [{
								id: 1,
								name: '老红糖牛乳波波',
								content: '“鲜甜桃肉x红颜草莓x茉莉绿茶 新鲜红颜草莓手工捣制，融入香甜桃子，搭配清新优雅的茉莉花香，满满果肉，清爽回甘！',
								price: 16,
								img: require("../../static/goods/003001.png"),
								num: 0
							},
							{
								id: 2,
								name: '鲜柠檬百香果',
								content: '“鲜甜桃肉x红颜草莓x茉莉绿茶 新鲜红颜草莓手工捣制，融入香甜桃子，搭配清新优雅的茉莉花香，满满果肉，清爽回甘！',
								price: 16,
								img: require("../../static/goods/003002.png"),
								num: 0
							},
							{
								id: 3,
								name: '超厚芋泥奶绿（大杯）',
								content: '“鲜甜桃肉x红颜草莓x茉莉绿茶 新鲜红颜草莓手工捣制，融入香甜桃子，搭配清新优雅的茉莉花香，满满果肉，清爽回甘！',
								price: 16,
								img: require("../../static/goods/003003.png"),
								num: 0
							},
							{
								id: 4,
								name: '桃气乌龙波波',
								content: '“鲜甜桃肉x红颜草莓x茉莉绿茶 新鲜红颜草莓手工捣制，融入香甜桃子，搭配清新优雅的茉莉花香，满满果肉，清爽回甘！',
								price: 10,
								img: require("../../static/goods/003004.png"),
								num: 0
							},
							{
								id: 5,
								name: '茉香奶绿',
								content: '“鲜甜桃肉x红颜草莓x茉莉绿茶 新鲜红颜草莓手工捣制，融入香甜桃子，搭配清新优雅的茉莉花香，满满果肉，清爽回甘！',
								price: 9,
								img: require("../../static/goods/003005.png"),
								num: 0
							},
							{
								id: 6,
								name: '冰淇淋奶茶',
								content: '“鲜甜桃肉x红颜草莓x茉莉绿茶 新鲜红颜草莓手工捣制，融入香甜桃子，搭配清新优雅的茉莉花香，满满果肉，清爽回甘！',
								price: 11,
								img: require("../../static/goods/003006.png"),
								num: 0
							},
							{
								id: 7,
								name: '薄荷奶绿',
								content: '“鲜甜桃肉x红颜草莓x茉莉绿茶 新鲜红颜草莓手工捣制，融入香甜桃子，搭配清新优雅的茉莉花香，满满果肉，清爽回甘！',
								price: 12,
								img: require("../../static/goods/003007.png"),
								num: 0
							},
							{
								id: 8,
								name: '鸭屎香波霸',
								content: '“鲜甜桃肉x红颜草莓x茉莉绿茶 新鲜红颜草莓手工捣制，融入香甜桃子，搭配清新优雅的茉莉花香，满满果肉，清爽回甘！',
								price: 11,
								img: require("../../static/goods/003008.png"),
								num: 0
							},
							{
								id: 9,
								name: '鲜柠檬奶绿',
								content: '“鲜甜桃肉x红颜草莓x茉莉绿茶 新鲜红颜草莓手工捣制，融入香甜桃子，搭配清新优雅的茉莉花香，满满果肉，清爽回甘！',
								price: 12,
								img: require("../../static/goods/003009.png"),
								num: 0
							},
							{
								id: 10,
								name: '茉香大满贯',
								content: '“鲜甜桃肉x红颜草莓x茉莉绿茶 新鲜红颜草莓手工捣制，融入香甜桃子，搭配清新优雅的茉莉花香，满满果肉，清爽回甘！',
								price: 12,
								img: require("../../static/goods/003010.png"),
								num: 0
							},
							{
								id: 11,
								name: '3Q芋圆奶茶',
								content: '“鲜甜桃肉x红颜草莓x茉莉绿茶 新鲜红颜草莓手工捣制，融入香甜桃子，搭配清新优雅的茉莉花香，满满果肉，清爽回甘！',
								price: 10,
								img: require("../../static/goods/003011.png"),
								num: 0
							},
							{
								id: 12,
								name: '黄金波霸奶茶',
								content: '“鲜甜桃肉x红颜草莓x茉莉绿茶 新鲜红颜草莓手工捣制，融入香甜桃子，搭配清新优雅的茉莉花香，满满果肉，清爽回甘！',
								price: 10,
								img: require("../../static/goods/003012.png"),
								num: 0
							},
							{
								id: 13,
								name: '阿萨姆奶茶',
								content: '“鲜甜桃肉x红颜草莓x茉莉绿茶 新鲜红颜草莓手工捣制，融入香甜桃子，搭配清新优雅的茉莉花香，满满果肉，清爽回甘！',
								price: 8,
								img: require("../../static/goods/003013.png"),
								num: 0
							}, {
								id: 14,
								name: '红豆奶茶',
								content: '“鲜甜桃肉x红颜草莓x茉莉绿茶 新鲜红颜草莓手工捣制，融入香甜桃子，搭配清新优雅的茉莉花香，满满果肉，清爽回甘！',
								price: 10,
								img: require("../../static/goods/003014.png"),
								num: 0
							},
							{
								id: 15,
								name: '椰果奶茶',
								content: '“鲜甜桃肉x红颜草莓x茉莉绿茶 新鲜红颜草莓手工捣制，融入香甜桃子，搭配清新优雅的茉莉花香，满满果肉，清爽回甘！',
								price: 10,
								img: require("../../static/goods/003015.png"),
								num: 0
							}
						]
					},
					{
						id: 4,
						name: '现磨咖啡',
						iconimg: require("../../static/menu/order_menu_4.png"),
						goodlist: [{
								id: 1,
								name: '生椰拿铁（小）',
								content: '“鲜甜桃肉x红颜草莓x茉莉绿茶 新鲜红颜草莓手工捣制，融入香甜桃子，搭配清新优雅的茉莉花香，满满果肉，清爽回甘！',
								price: 14,
								img: require("../../static/goods/004001.png"),
								num: 0
							},
							{
								id: 2,
								name: '美式咖啡（中）',
								content: '“鲜甜桃肉x红颜草莓x茉莉绿茶 新鲜红颜草莓手工捣制，融入香甜桃子，搭配清新优雅的茉莉花香，满满果肉，清爽回甘！',
								price: 11,
								img: require("../../static/goods/004002.png"),
								num: 0
							},
							{
								id: 3,
								name: '雪顶冰咖啡',
								content: '“鲜甜桃肉x红颜草莓x茉莉绿茶 新鲜红颜草莓手工捣制，融入香甜桃子，搭配清新优雅的茉莉花香，满满果肉，清爽回甘！',
								price: 13,
								img: require("../../static/goods/004003.png"),
								num: 0
							}
						]
					},
					{
						id: 5,
						name: '天然海风·椰',
						iconimg: require("../../static/menu/order_menu_5.png"),
						goodlist: [{
								id: 1,
								name: '桃气鲜椰乳',
								content: '“鲜甜桃肉x红颜草莓x茉莉绿茶 新鲜红颜草莓手工捣制，融入香甜桃子，搭配清新优雅的茉莉花香，满满果肉，清爽回甘！',
								price: 16,
								img: require("../../static/goods/005001.png"),
								num: 0
							},
							{
								id: 2,
								name: '茉莉鲜椰乳',
								content: '“鲜甜桃肉x红颜草莓x茉莉绿茶 新鲜红颜草莓手工捣制，融入香甜桃子，搭配清新优雅的茉莉花香，满满果肉，清爽回甘！',
								price: 16,
								img: require("../../static/goods/005002.png"),
								num: 0
							},
							{
								id: 3,
								name: '葡萄生打椰',
								content: '“鲜甜桃肉x红颜草莓x茉莉绿茶 新鲜红颜草莓手工捣制，融入香甜桃子，搭配清新优雅的茉莉花香，满满果肉，清爽回甘！',
								price: 16,
								img: require("../../static/goods/005003.png"),
								num: 0
							},
							{
								id: 4,
								name: '生打椰椰',
								content: '“鲜甜桃肉x红颜草莓x茉莉绿茶 新鲜红颜草莓手工捣制，融入香甜桃子，搭配清新优雅的茉莉花香，满满果肉，清爽回甘！',
								price: 15,
								img: require("../../static/goods/005004.png"),
								num: 0
							},
							{
								id: 5,
								name: '桃桃生打椰',
								content: '“鲜甜桃肉x红颜草莓x茉莉绿茶 新鲜红颜草莓手工捣制，融入香甜桃子，搭配清新优雅的茉莉花香，满满果肉，清爽回甘！',
								price: 16,
								img: require("../../static/goods/005005.png"),
								num: 0
							}
						]
					},
					{
						id: 6,
						name: '鲜沏茶',
						iconimg: require("../../static/menu/order_menu_6.png"),
						goodlist: [{
								id: 1,
								name: '桃气乌龙',
								content: '“鲜甜桃肉x红颜草莓x茉莉绿茶 新鲜红颜草莓手工捣制，融入香甜桃子，搭配清新优雅的茉莉花香，满满果肉，清爽回甘！',
								price: 6,
								img: require("../../static/goods/006001.png"),
								num: 0
							},
							{
								id: 2,
								name: '茉香绿茶',
								content: '“鲜甜桃肉x红颜草莓x茉莉绿茶 新鲜红颜草莓手工捣制，融入香甜桃子，搭配清新优雅的茉莉花香，满满果肉，清爽回甘！',
								price: 6,
								img: require("../../static/goods/006001.png"),
								num: 0
							},
							{
								id: 3,
								name: '蜂蜜绿茶',
								content: '“鲜甜桃肉x红颜草莓x茉莉绿茶 新鲜红颜草莓手工捣制，融入香甜桃子，搭配清新优雅的茉莉花香，满满果肉，清爽回甘！',
								price: 7,
								img: require("../../static/goods/006001.png"),
								num: 0
							},
						]
					}
				]
			}
		},
		async onLoad() {
			await this.init
		},
		onShow() {
			//address
			let that = this;
			console.log("页面onShow");
		},
		onReady() {
			let that = this;
			uni.hideLoading()
			uni.chooseLocation({
				success: function(res) {
					that.getPlistData.lat = res.latitude;
					that.getPlistData.lng = res.longitude;
					that.addressTop = res.address;
					that.getPlistData.name = res.name;
					// console.log('位置名称：' + res.name);
					// console.log('详细地址：' + res.address);
					// console.log('纬度：' + res.latitude);
					// console.log('经度：' + res.longitude);

				},
				fail: function(res) {
					console.log(res, "经纬度没有授权")
					uni.getSetting({
						success: (res) => {
							let authSetting = res.authSetting;
							if (!res.authSetting['scope.userLocation']) {
								uni.showModal({
									title: '您未开启地理位置授权',
									content: '请前往开启定位',
									success: (res) => {
										if (res.confirm) {
											uni.openSetting()
										}
									}
								})
							} else {
								uni.showModal({
									title: '您未开启手机地理位置',
									content: '请前往开启定位',
									success: (res) => {
										if (res.confirm) {
											uni.openSetting()
										}
									}
								})
							}
						}
					})
				}
			})
		},
		computed: {
			goodCartNum() {
				return (id) => this.cart.reduce((acc, cur) => {
					if (cur.id === id) {
						return acc += cur.number
					}
					return acc
				}, 0)
			},
			menuCartNum() {
				return (id) => this.cart.reduce((acc, cur) => {
					if (cur.cate_id === id) {
						return acc += cur.number
					}
					return acc
				}, 0)
			},
			//获取cart数量
			getCartGoodsNumber() {
				//计算购物车总数
				return this.cart.reduce((acc, cur) => acc + cur.number, 0)
			},
			getCartGoodsPrice() {
				//计算购物车总价
				return this.cart.reduce((acc, cur) => acc + cur.number * cur.price, 0)
			},
			disabledPay() {
				//是否达到起送价
				return this.arr.key == 0 && this.getCartGoodsPrice < 15 ? true : false
			}
		},
		methods: {
			async init() {
				//页面初始化
				this.loading = true
				await this.$api('goods')
				this.loading = false
				this.cart = uni.getStorageSync('cart') || []
			},
			getSwitchValue(e) {
				console.log(e.key)
				uni.showToast({
					icon: 'none',
					title: '已切换到' + (e.key == 1 ? "外卖餐品" : "自取餐品")
				})
			},
			toPay() {
				uni.navigateTo({
					url: '/pages/pay/pay'
				});
			},

			handleMenuTap(id) {
				//点击菜单项事件
				if (!this.sizeCalcState) {
					this.calcSize()
				}
				this.currentCateId = id
				this.$nextTick(() => this.cateScrollTop = this.goods.find(item => item.id == id).top)
			},
			handleGoodsScroll({
				detail
			}) {
				//商品列表滚动事件
				if (!this.sizeCalcState) {
					this.calcSize()
				}
				const {
					scrollTop
				} = detail
				let tabs = this.goods.filter(item => item.top <= scrollTop).reverse()
				if (tabs.length > 0) {
					this.currentCateId = tabs[0].id
				}
			},
			calcSize() {
				let h = 10
				let view = uni.createSelectorQuery().select('#ads')
				view.fields({
					size: true
				}, data => {
					h += Math.floor(data.height)
				}).exec()
				this.goods.forEach(item => {
					let view = uni.createSelectorQuery().select(`#cate-${item.id}`)
					view.fields({
						size: true
					}, data => {
						item.top = h
						h += data.height
						item.bottom = h
					}).exec()
				})
				this.sizeCalcState = true
			},

			//商品详情页面
			showGoodDetailModal(item, good) {
				this.good = JSON.parse(JSON.stringify({
					...good,
					number: 1
				}))
				this.category = JSON.parse(JSON.stringify(item))
				this.goodDetailModalVisible = true
			},
			closeGoodDetailModal() {
				this.goodDetailModalVisible = false
				this.category = {}
				this.good = {}
			},
			handlePropertyAdd() {
				this.good.number += 1
			},
			handlePropertyReduce() {
				if (this.good.number === 1) return
				this.good.number -= 1
			},
			handleAddToCartInModal() {
				const product = Object.assign({}, this.good, {
					props_text: this.getGoodSelectedProps(this.good),
					props: this.getGoodSelectedProps(this.good, 'id')
				})
				this.handleAddToCart(this.category, product, this.good.number)
				this.closeGoodDetailModal()
			},
			getGoodSelectedProps(good, type = 'text') {
				//计算当前所选属性
				if (good.use_property) {
					let props = []
					good.property.forEach(({
						values
					}) => {
						values.forEach(value => {
							if (value.is_default) {
								props.push(type === 'text' ? value.value : value.id)
							}
						})
					})
					return type === 'text' ? props.join('，') : props
				}
				return ''
			},
			changePropertyDefault(index, key) {
				this.good.property[index].values.forEach(value => this.$set(value, 'is_default', 0))
				this.good.property[index].values[key].is_default = 1
				this.good.number = 1
			},

			handleReduceFromCart(item, good) {
				const index = this.cart.findIndex(item => item.key === good.key)
				this.cart[index].number -= 1
				if (this.cart[index].number <= 0) {
					this.cart.splice(index, 1)
				}
			},
			handleAddToCart(cate, good, num) {
				//添加到购物车
				const index = this.cart.findIndex(item => {
					if (good.use_property) {
						return (item.key === good.key) && (item.props_text === good.props_text)
					} else {
						return item.key === good.key
					}
				})
				if (index > -1) {
					this.cart[index].number += num
				} else {
					this.cart.push({
						key: good.key,
						cate_key: cate.key,
						name: good.name,
						price: good.price,
						number: num,
						image: good.images,
						use_property: good.use_property,
						props_text: good.props_text,
						props: good.props
					})
				}
			},
			//获取地址列表
			getAddressList() {
				let that = this;
				uni.chooseLocation({
					success: function(res) {
						that.getPlistData.lat = res.latitude;
						that.getPlistData.lng = res.longitude;
						that.addressTop = res.address;
						that.getPlistData.name = res.name;
					},
					fail: function(res) {
						console.log(res, "经纬度没有授权")
						uni.getSetting({
							success: (res) => {
								let authSetting = res.authSetting;
								if (!res.authSetting['scope.userLocation']) {
									uni.showModal({
										title: '您未开启地理位置授权',
										content: '请前往开启定位',
										success: (res) => {
											if (res.confirm) {
												uni.openSetting()
											}
										}
									})
								} else {
									uni.showModal({
										title: '您未开启手机地理位置',
										content: '请前往开启定位',
										success: (res) => {
											if (res.confirm) {
												uni.openSetting()
											}
										}
									})
								}
							}
						})
					},
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	@import '@/pages/order/order.scss';

	.mr-10 {
		margin-right: 12px;
	}
</style>
